{% extends 'dns_manager/base.html' %}
{% load crispy_forms_tags %}

{% block title %}云账号管理 - DNS管理系统{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h2 class="mb-1">
            <i class="bi bi-cloud-check text-primary me-2"></i>云账号管理
        </h2>
        <p class="text-muted mb-0">管理多个云服务商账号配置</p>
    </div>
    <a href="{% url 'create_cloud_account' %}" class="btn btn-primary">
        <i class="bi bi-plus me-1"></i>添加云账号
    </a>
</div>

{% if accounts %}
<div class="row g-4">
    {% for account in accounts %}
    <div class="col-lg-6 col-xl-4">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-body">
                <div class="d-flex align-items-start justify-content-between mb-3">
                    <div class="flex-grow-1">
                        <h5 class="card-title mb-1">{{ account.name }}</h5>
                        <div class="d-flex align-items-center">
                            {% if account.provider == 'aliyun' %}
                                <span class="badge bg-primary me-2">阿里云</span>
                            {% elif account.provider == 'tencent' %}
                                <span class="badge bg-success me-2">腾讯云</span>
                            {% elif account.provider == 'huawei' %}
                                <span class="badge bg-warning me-2">华为云</span>
                            {% elif account.provider == 'volcengine' %}
                                <span class="badge bg-danger me-2">火山引擎</span>
                            {% endif %}
                            
                            {% if account.is_active %}
                                <span class="badge bg-light text-success">
                                    <i class="bi bi-check-circle me-1"></i>启用
                                </span>
                            {% else %}
                                <span class="badge bg-light text-danger">
                                    <i class="bi bi-x-circle me-1"></i>禁用
                                </span>
                            {% endif %}
                        </div>
                    </div>
                    
                    <div class="dropdown">
                        <button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="dropdown">
                            <i class="bi bi-three-dots-vertical"></i>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li>
                                <a class="dropdown-item" href="{% url 'sync_cloud_account' account.id %}">
                                    <i class="bi bi-arrow-clockwise me-2"></i>同步域名
                                </a>
                            </li>
                            <li><hr class="dropdown-divider"></li>
                            <li>
                                <a class="dropdown-item" href="{% url 'edit_cloud_account' account.id %}">
                                    <i class="bi bi-pencil me-2"></i>编辑
                                </a>
                            </li>
                            <li><hr class="dropdown-divider"></li>
                            <li>
                                <a class="dropdown-item text-danger" href="{% url 'delete_cloud_account' account.id %}">
                                    <i class="bi bi-trash me-2"></i>删除
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="account-details">
                    <div class="row g-2 mb-3">
                        <div class="col-4">
                            <small class="text-muted">Access Key:</small>
                        </div>
                        <div class="col-8">
                            <small class="text-truncate d-block" style="max-width: 120px;">
                                {{ account.access_key }}
                            </small>
                        </div>
                    </div>
                    
                    {% if account.region %}
                    <div class="row g-2 mb-3">
                        <div class="col-4">
                            <small class="text-muted">地域:</small>
                        </div>
                        <div class="col-8">
                            <small>{{ account.region }}</small>
                        </div>
                    </div>
                    {% endif %}
                    
                    <div class="row g-2">
                        <div class="col-4">
                            <small class="text-muted">创建时间:</small>
                        </div>
                        <div class="col-8">
                            <small class="text-muted">{{ account.created_at|date:"Y-m-d" }}</small>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="card-footer bg-light border-0">
                <div class="row g-2">
                    <div class="col">
                        <small class="text-muted">
                            <i class="bi bi-globe me-1"></i>
                            域名: {{ account.domain_set.count }}
                        </small>
                    </div>
                    <div class="col text-end">
                        <small class="text-muted">
                            最后更新: {{ account.updated_at|date:"m-d H:i" }}
                        </small>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% endfor %}
</div>
{% else %}
<div class="text-center py-5">
    <div class="mb-4">
        <i class="bi bi-cloud-slash text-muted" style="font-size: 4rem;"></i>
    </div>
    <h4 class="text-muted mb-3">还没有配置云账号</h4>
    <p class="text-muted mb-4">
        开始添加您的第一个云账号，以便管理域名解析
    </p>
    <a href="{% url 'create_cloud_account' %}" class="btn btn-primary btn-lg">
        <i class="bi bi-plus me-2"></i>添加云账号
    </a>
</div>
{% endif %}

<style>
.account-details {
    font-size: 0.875rem;
}

.card {
    transition: transform 0.2s ease-in-out;
}

.card:hover {
    transform: translateY(-2px);
}
</style>
{% endblock %}